package com.sto.stoapp.widget;

import android.os.Bundle;
import android.util.Log;

import com.sto.stoapp.StoApplication;
import com.sto.stoapp.db.StoFilePreference;

import sto.android.app.StoJNI;

/**
 * 申通扫描类
 * 
 * @author mgf
 * 
 */
public abstract class StoScanActivity extends StoHomeActivity implements
		StoJNI.ScanCallBack {

	private StoJNI kaicomJNI;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		kaicomJNI = StoApplication.getStoJni();
		kaicomJNI.setmScanCB(this);
		kaicomJNI.SetScannerOn();
		System.out.println("StoScanActivity:SetScannerOn");
	}

	public void startScan() {
		if (kaicomJNI != null) {
			Log.d("ScanOpen", "kaicomJNI.SetScannerStart()");
			int outTime= StoFilePreference.getInstance(this).getScanHeaderTime();
			if(outTime>0){
//				kaicomJNI.SetScannerTimerOut(outTime);
			}
			kaicomJNI.SetScannerStart();
		}
	}

	public void endScan() {
		if (kaicomJNI != null) {
			kaicomJNI.SetScannerStop();
		}
	}

	public void scanContinue() {
		if (kaicomJNI != null) {
			kaicomJNI.SetScannerRetriger();
		}
	}

	public boolean scanStatus() {
		if (kaicomJNI != null) {
			return kaicomJNI.GetScannerIsScanning();
		}
		return false;
	}

	@Override
	protected void onDestroy() {
		System.out.println("StoScanActivity : StoScanActivity  onDestroy");
		super.onDestroy();
		// if (kaicomJNI != null) {
		// kaicomJNI.SetScannerStop();
		// kaicomJNI.SetScannerOff();
		// System.out.println("StoScanActivity:SetScannerOff");
		// kaicomJNI = null;
		// }
	}

	public void setScanTimeOut(int time) {
		if (kaicomJNI != null) {
			kaicomJNI.SetScannerTimerOut(time);
		}
	}



	@Override
	protected void doBluetoothBack() {
		System.out.println("StoScanActivity:doBluetoothBack");
		if (kaicomJNI != null) {
			kaicomJNI.SetScannerStop();
			kaicomJNI.SetScannerOff();
			System.out.println("StoScanActivity:SetScannerOff");
			kaicomJNI = null;
		}
		super.doBluetoothBack();
	}

}
